<?php
require('common/common.php');

$Input = new Input();
$username = $Input->get('username');
$passwd = $Input->get('passwd');
$passwd2 = $Input->get('passwd2');
$email = $Input->get('email');

if (isset($username)) {
    try {
        User::initialize(db_connect());
        $user = User::create(array(
            'name'=>$username,
            'email'=>$email,
            'passwd'=>$passwd
            ));
        $user->save();
        $message = "User $username created!";
    } catch(Exception $e) {
        $message = 'Error: '.$e->getMessage();
    }
}

?>
<!DOCTYPE html>
<HTML><head>
    <title>New User</title>
</head>
<body>
    <div id="header"></div><br>
    <div id="main"><?php
        if (isset($message)) { 
            echo "<h3>$message</h3>\n";
        }
    ?>
    <h2>New User:</h2>
    <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" >
        <label>Username: </label><input type="text" name="username" ><br>
        <label>Email: </label><input type="text" name="email" ><br>
        <label>Password: </label><input type="password" name="passwd" ><br>
        <label>Re-enter Password: </label><input type="password" name="passwd2" ><br>
        <input type="submit">
    </form>
    </div>
</body></HTML>